package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.domain.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbHouseMapper;
import com.ruoyi.system.domain.TbHouse;
import com.ruoyi.system.service.ITbHouseService;

/**
 * 房源Service业务层处理
 *
 * @author 姚炜琦
 * @date 2022-10-19
 */
@Service
public class TbHouseServiceImpl implements ITbHouseService
{
    @Autowired
    private TbHouseMapper tbHouseMapper;

    /**
     * 查询房源
     *
     * @param id 房源主键
     * @return 房源
     */
    @Override
    public TbHouse selectTbHouseById(Long id)
    {
        return tbHouseMapper.selectTbHouseById(id);
    }

    /**
     * 查询房源列表
     *
     * @param tbHouse 房源
     * @return 房源
     */
    @Override
    public List<TbHouse> selectTbHouseList(TbHouse tbHouse)
    {
        return tbHouseMapper.selectTbHouseList(tbHouse);
    }

    /**
     * 新增房源
     *
     * @param tbHouse 房源
     * @return 结果
     */
    @Override
    public int insertTbHouse(TbHouse tbHouse)
    {
        // 新增房源时生成唯一的雪花ID
        SnowFlakeUtil snowFlakeUtil = new SnowFlakeUtil();
        String snowId = String.valueOf(snowFlakeUtil.snowflakeId());
        tbHouse.setSnowflake(snowId);
        tbHouse.setCreateTime(DateUtils.getNowDate());
        return tbHouseMapper.insertTbHouse(tbHouse);
    }

    /**
     * 修改房源
     *
     * @param tbHouse 房源
     * @return 结果
     */
    @Override
    public int updateTbHouse(TbHouse tbHouse)
    {
        return tbHouseMapper.updateTbHouse(tbHouse);
    }

    /**
     * 批量删除房源
     *
     * @param ids 需要删除的房源主键
     * @return 结果
     */
    @Override
    public int deleteTbHouseByIds(Long[] ids)
    {
        return tbHouseMapper.deleteTbHouseByIds(ids);
    }

    /**
     * 删除房源信息
     *
     * @param id 房源主键
     * @return 结果
     */
    @Override
    public int deleteTbHouseById(Long id)
    {
        return tbHouseMapper.deleteTbHouseById(id);
    }
}
